package database.entitymanager;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EntityFactoryHolder {
	private EntityManagerFactory emf;
	public static final String persistenceName = "WebshopITE";

	private EntityFactoryHolder() {
		emf = Persistence.createEntityManagerFactory(persistenceName);
	}

	/**
	 * SingletonHolder is loaded on the first execution of
	 * Singleton.getInstance() or the first access to SingletonHolder.INSTANCE,
	 * not before.
	 */
	private static class SingletonHolder {
		public static final EntityFactoryHolder INSTANCE = new EntityFactoryHolder();
	}

	public static EntityManagerFactory getInstance() {
		return SingletonHolder.INSTANCE.getEmf();
	}

	public void setEmf(EntityManagerFactory emf) {
		this.emf = emf;
	}

	public EntityManagerFactory getEmf() {
		return emf;
	}
}
